
Class('userlogin', 'linb.Com',{
    Instance:{
        //base Class for this com
        base:["linb.UI"], 
        //requried class for this com
        required:["linb.UI.Pane", "linb.UI.Label", "linb.UI.Input", "linb.UI.Button", "linb.UI.Dialog"], 
        parents: null,
        haslogin:null,
        properties:{}, 
        events:{"onRender":"_onrender"}, 
        iniResource:function(com, threadid){
        }, 
        iniExComs:function(com, hreadid){
        }, 
        iniComponents:function(){
            // [[code created by jsLinb UI Builder
            var host=this, children=[], append=function(child){children.push(child.get(0));};
            
            dlg = (new linb.UI.Dialog)
                .host(host,"dialog1")
                .setLeft(140)
                .setTop(99)
                .setWidth(480)
                .setHeight(280)
                .setCaption("用户登录")
                .setMinBtn(false)
                .setMaxBtn(false)
                .beforeDestroy("_dialog1_beforedestroy");
            
            append(dlg);
            
            host.dialog1.append((new linb.UI.Label)
                .host(host,"label1")
                .setLeft(80)
                .setTop(80)
                .setWidth(70)
                .setCaption("用户名")
            );
            
            host.dialog1.append((new linb.UI.Label)
                .host(host,"label2")
                .setLeft(80)
                .setTop(130)
                .setWidth(70)
                .setCaption("口令")
            );
            
            host.dialog1.append((new linb.UI.Input)
                .host(host,"username")
                .setLeft(160)
                .setTop(80)
            );
            
            host.dialog1.append((new linb.UI.Input)
                .host(host,"password")
                .setLeft(160)
                .setTop(130)
            );
            
            host.dialog1.append((new linb.UI.Button)
                .host(host,"button8")
                .setLeft(320)
                .setTop(100)
                .setWidth(90)
                .setHeight(40)
                .setCaption("登录")
                .onClick("_button8_onclick")
            );
            
            return children;
            // ]]code created by jsLinb UI Builder
        }, 
        _button8_onclick:function (profile, e, src, value) {
            self = this;
            ss = "{'"+"username"+"':'"+self.username.getUIValue()+"','"+"password"+"':'"+self.password.getUIValue()+"'"+"}"
            linb.request("/NetDM4Web/userlogin.do","cmd=login&datas="+ss,            
            function(rep){
                var obj = _.unserialize(rep);
		        if (obj.code == 0) {
			    	linb.UI.Dialog.alert('提示',obj.messages);
				    haslogin = 1;
	                if (parents != null) {
    	                o = _.unserialize(obj.datas);
    	                parents.setrole(o.role);
            	    }
            	    dlg.close();
                } else {
                    linb.UI.Dialog.alert('提示',obj.messages);
                }
                
            },
            function() {
            	linb.UI.Dialog.alert('提示','网络出现问题，登录系统失败，请稍候再试。');
            });
        },
        _onrender:function (com, threadid) {
           haslogin =0;
        },         
        _dialog1_beforedestroy:function (profile) {
            self = this;
            if (parents != null && haslogin!=1) {
                oo = _.unserialize(parents.menubar1.getTagVar());
                oo.mlogin= 0;
                parents.menubar1.setTagVar(_.serialize(oo));
            }
            return true;
        },
        setWhoisParent: function (parent_obj) {
            parents = parent_obj;
        }
    }
});